package com.example.demo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rest")
@Api(tags = "RESTful 接口")
public class RestFulController {

    @GetMapping("/swagger")
    @ApiOperation(value = "Swagger 接口")
    public String swagger() {
        return "Swagger Method";
    }

    @GetMapping("/user/{id}")
    @ApiOperation(value = "根据id获取用户信息")
    public User get(@PathVariable int id) {
        User user = new User();
        user.setId(id);
        user.setName("ID为"+id+"的用户");
        user.setAge(18);
        user.setEmail("shuijing@mail.com");
        return user;
    }
    @PostMapping("/user")
    public boolean create(@RequestBody User user) {
        if (user != null) {
            return true;
        }
        return false;
    }

    @PutMapping("/user")
    public boolean update(@RequestBody User user) {
        if (user != null) {
            return true;
        };
        return false;
    }

    @DeleteMapping("/user/{id}")
    public boolean delete(@PathVariable int id) {
        if(id > 0) {
            return true;
        }
        return false;
    }
}
